/**
 * 
 */
package kr.co.insoft.core.repository.configration.sev.impl;

import java.util.List;

import kr.co.insoft.core.mapper.configration.sev.SEVMetadataEntityMapper;
import kr.co.insoft.core.model.configration.sev.SEVEntityModel;
import kr.co.insoft.core.model.configration.sev.SEVMetadataEntityModel;
import kr.co.insoft.core.repository.configration.sev.SEVMetadataRepository;
import kr.co.insoft.framework.exceptions.ExceptionCode;
import kr.co.insoft.framework.exceptions.RepositoryException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.util.Assert;

/**
 * @author IN-SOFT Inc. GoodwillDD(sylee@in-soft.co.kr)
 * 
 */
@Repository
public class SEVMetadataRepositoryImpl implements SEVMetadataRepository {

	private static final Logger SEVMetadataRepositoryImplLog = LoggerFactory
			.getLogger(SEVMetadataRepositoryImpl.class);

	@Autowired
	SEVMetadataEntityMapper sevMetadataEntityMapper;

	@Override
	public void createSEVMetadata(SEVEntityModel sevEntityModel)
			throws RepositoryException {
		try {
			Assert.notNull(sevEntityModel.getVariableid());
			Assert.notEmpty(sevEntityModel.getVariables());
		} catch (IllegalArgumentException e) {
			SEVMetadataRepositoryImplLog.error(ExceptionCode.ASSERT_FORMAT, sevEntityModel.getVariableid());
			SEVMetadataRepositoryImplLog.error(ExceptionCode.ASSERT_FORMAT, sevEntityModel.getVariables());
			throw new RepositoryException(ExceptionCode.ARGUMENT_ERROR);
		}

		try {
			sevMetadataEntityMapper.createSEVMetadata(sevEntityModel);
		} catch (Exception e) {
			throw new RepositoryException(ExceptionCode.REPOSITORY_EXCEPTION, e);
		}
	}

	/**
	 * Not Used -  사용하게 되면 Deprecated 해제
	 */
	@Deprecated
	@Override
	public List<SEVMetadataEntityModel> getSEVMetadata(
			SEVEntityModel sevEntityModel) throws RepositoryException {
		try {
			Assert.notNull(sevEntityModel.getVariableid());
		} catch (IllegalArgumentException e) {
			SEVMetadataRepositoryImplLog.error(ExceptionCode.ASSERT_FORMAT, sevEntityModel.getVariableid());
			throw new RepositoryException(ExceptionCode.ARGUMENT_ERROR);
		}

		try {
			return sevMetadataEntityMapper.getSEVMetadata(sevEntityModel);
		} catch (Exception e) {
			throw new RepositoryException(ExceptionCode.REPOSITORY_EXCEPTION, e);
		}
	}

	@Override
	public void removeSEVMetadata(SEVEntityModel sevEntityModel)
			throws RepositoryException {
		try {
			Assert.notNull(sevEntityModel.getVariableid());
		} catch (IllegalArgumentException e) {
			SEVMetadataRepositoryImplLog.error(ExceptionCode.ASSERT_FORMAT, sevEntityModel.getVariableid());
			throw new RepositoryException(ExceptionCode.ARGUMENT_ERROR);
		}

		try {
			sevMetadataEntityMapper.removeSEVMetadata(sevEntityModel);
		} catch (Exception e) {
			throw new RepositoryException(ExceptionCode.REPOSITORY_EXCEPTION, e);
		}
	}
}
